package com.shy.controller;

import com.alibaba.fastjson.JSON;
import com.shy.bean.Person;
import com.shy.bean.User;
import com.shy.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.UUID;

@RestController
public class RedisController {
    @Autowired
    private RedisUtil redisUtil;


    @GetMapping("/redis")
    public String redisAdd() {
        String key = UUID.randomUUID().toString().replace("-", "").substring(0, 10);
        for (int i = 0; i < 100; i++) {
            User user = new User();
            user.setId(UUID.randomUUID().toString().replace("-", "").substring(0, 10));
            user.setName(UUID.randomUUID().toString().replace("-", ""));
            user.setPsd(UUID.randomUUID().toString());

            String jsonString = JSON.toJSONString(user);
            HashMap<String, String> map = new HashMap<>();
            map.put( UUID.randomUUID().toString().replace("-", "").substring(0, 10), jsonString);
            redisUtil.hmset(key, map);
        }
        redisUtil.close();
        return "redis add success";
    }
}
